package com.ebuy.shopping.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ebuy.shopping.mapper.CategoryMapper;
import com.ebuy.shopping.model.Category;

@Service
public class CategoryService implements ICategoryService
{
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Category load(int id) throws Exception
    {
        return categoryMapper.selectByPrimaryKey(id);

    }

    @Override
    public int add(Category category) throws Exception
    {
        return categoryMapper.insert(category);

    }

    @Override
    public int update(Category category) throws Exception
    {
        return categoryMapper.updateByPrimaryKey(category);

    }

    @Override
    public List<Category> getCategories()
    {
        return categoryMapper.getCategories();

    }

    @Override
    public List<Category> getCategoriesByIndex() throws Exception
    {

        return categoryMapper.getCategoriesByIndex();

    }

    @Override
    public List<Category> getCategoriesBySecondIndex() throws Exception
    {

        return categoryMapper.getCategoriesBySecondIndex();

    }

    @Override
    public List<Category> getCategoriesByParentId(int parentId)
            throws Exception
    {

        return categoryMapper.getCategoriesByParentId(parentId);

    }

    @Override
    public List<Category> getCategoriesByGrade(int grade) throws Exception
    {

        return categoryMapper.getCategoriesByGrade(grade);

    }

    @Override
    public int delete(int id) throws Exception
    {

        return categoryMapper.deleteByPrimaryKey(id);

    }
}
